package com.wiley.searchPO;

import io.appium.java_client.android.AndroidDriver;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;

import com.wiley.publicMethod.BasePage;
import com.wiley.publicMethod.LoggerControler;

import java.io.IOException;
import java.net.MalformedURLException;

public class StorePage extends BasePage {

	/**
	 * 页面元素
	 */
	//到家
	public static final By store_item_loc = By.id(BaseId + "store_item");
	
	//搜索商品
	public static final By goods_bar_search_loc = By.id(BaseId + "goods_bar_search");

	//点击搜索框弹出的输入框
	public static final By goods_input_loc = By.id(BaseId + "search_src_text");
	
	//搜索列表封面图片
	public static final By goods_cover_loc = By.id(BaseId + "goods_cover");
	
	//该商品的描述
	public static final By goods_title_loc = By.id(BaseId+"title");
	
	/**
	 * 操作方法
	 */
	//点击到家
	public void clickStoreItem(){
		this.clickEle(store_item_loc);
	}
	
	//点击搜索框，进入搜索页面
	public void clickGoodsBarSearchBox(){
		this.clickEle(goods_bar_search_loc);
	}

	//定位输入框，输入商品名称
	public void inputGoods(String recipe){
		this.sendKeys(goods_input_loc,recipe);
	}
	
	//点击封面图片
	public void clickGoodsCover(int i){
		this.clickEles(goods_cover_loc, i);
	}

	//商品名
	public String getGoodsName(){
		WebElement ele = this.findEle(goods_title_loc);
		return ele.getText();
	}
	/**
	 * 业务封装
	 * @throws MalformedURLException 
	 */
	public void storeSearch(String goods,Class name) throws MalformedURLException  {
		LoggerControler log = this.MyLogger(name);
		AndroidDriver driver = super.SetDriver();
		this.clickStoreItem();
		this.clickGoodsBarSearchBox();
		this.inputGoods(goods);
		log.info("本次搜索的商品是："+goods);
		driver.sendKeyEvent(66);
		this.clickGoodsCover(1);
		log.info("该商品名为："+this.getGoodsName());
		super.captureScreen("Search_goods_"+goods);
		log.info("该case测试通过");
	}
}
